<template>
  <div>
    <div class="student-item1">
     <van-cell-group>
       <van-cell title="日期"  @click="show=true">{{ time }}<van-icon name="arrow" style="line-height: inherit;margin-left: 20px;"/></van-cell>
     </van-cell-group>
    </div>
    <van-cell-group v-for="(item,index) in teacher" :key="index">
      <van-cell :title="item.name+'老师'">
      {{ item.sktime }}
      <van-icon slot="right-icon" name="records" size="20px" style="line-height: inherit;margin-left: 20px;" @click="$router.push({path: '/curriculumEdit', query: {data: item.kjid}})" />
        <!-- <img src="@/assets/img/icon-edit.png" alt="" width="20px"> -->
    </van-cell>
    </van-cell-group>
<!--    <div class="content" v-for="(item, index) in teacher" :key="index">
      <van-cell-group>
        <van-cell :title="item.name+'老师'" :value="item.statu" center :label="item.time" />
      </van-cell-group>
    </div> -->
      <van-popup v-model="show" position="bottom" >
       <van-datetime-picker v-model="currentDate" type="date" @cancel="show = false" @confirm="show = false"
           @change="endTimeChange" />
      </van-popup>
    </div>

</template>

<script>
import api from '@/api'
export default {
  name: 'student-edit',
  data () {
    return {
      time: '',
      ktime: '',
      jtime: '',
      show: false,
      currentDate: new Date(),
      teacher: []
    }
  },
  mounted () {
    this.getTime()
    this.managementListr()
  },
  methods: {
    // 课程管理列表 agencyManagementListr
    managementListr () {
      let params = {
        // mechanism_id: JSON.parse(sessionStorage.getItem('user')).id
        mechanism_id: JSON.parse(sessionStorage.getItem('user')).id,
        ktime: this.ktime,
        jtime: this.jtime
      }
      api.agencyManagementListr({
        params,
        callback: res => {
          console.log(res)
          this.teacher = res.data.data
          this.teacher.forEach(v => {
            if (v.sktime) {
              let date = new Date(parseInt(v.sktime) * 1000)
              let h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() +
                                      ':'
              let m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
              v.sktime = h + m
            }
          })
        }
      })
    },

    // 初始化时间
    getTime () {
      let date = new Date()
      let Y = date.getFullYear() + '-'
      let M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) + '-' : date.getMonth() + 1 + '-'
      let D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' '
      this.time = Y + M + D
      this.ktime = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime()
      this.ktime = (this.ktime) / 1000
      this.jtime = new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1).getTime()
      this.jtime = Number((this.jtime) / 1000) - Number(1)
    },
    endTimeChange (e) {
      let endTimeArr = e.getValues()
      this.time = `${endTimeArr[0]}-${endTimeArr[1]}-${endTimeArr[2]}`
      this.ktime = new Date(`${endTimeArr[0]}`, Number(`${endTimeArr[1]}`) - Number(1), `${endTimeArr[2]}`).getTime()
      this.ktime = (this.ktime) / 1000
      this.jtime = new Date(`${endTimeArr[0]}`, Number(`${endTimeArr[1]}`) - Number(1), Number(`${endTimeArr[2]}`) + Number(1)).getTime()
      this.jtime = Number((this.jtime) / 1000) - Number(1)
      this.managementListr()
    },
    formatter (type, value) {
      if (type === 'year') {
        return `${value}年`
      } else if (type === 'month') {
        return `${value}月`
      }
      return value
    }
  }
}
</script>

<style scoped>
  .student-item1 {
    line-height: 60px;
    align-items: center;
    border-bottom: 1px solid #999;
    box-shadow: 0 0 3px #999;
    position: relative;
    z-index: 100
  }
  .van-cell{
    line-height: 40px;
  }
  .van-cell span{
    font-size: 18px;
  }
</style>
